
#include "GameCreature.h"
#include "ExpConfig.h"

GameCreature::GameCreature()
:	mState( GCSSTAND ) , mType( GCTGUEST ) , 
	mDanger( 0 ) , mTeam( F_NULL )
{
	mTempExp = 0;

	ClearFightStatus();
}


GameCreature::~GameCreature()
{
	
}


fvoid					GameCreature::Init()
{
	
}


fvoid					GameCreature::Release()
{
    mMoveData.Clear();
    
	mDanger = 0;

	mType = GCTGUEST;
	mState = GCSSTAND;
	mData.ID = INVALID_ID;
    
	mTempExp = 0;

	ClearFightStatus();
}


fint32					GameCreature::GetGUID()
{
	return mData.ID;
}


fvoid					GameCreature::SetGUID( fint32 id )
{
	mData.ID = id;
    mMoveData.GUID = id;
}


fvoid					GameCreature::SetType( GameCreatureType type )
{
	mType = type;
}


GameCreature::GameCreatureType		GameCreature::GetType()
{
	return mType;
}


fbool					GameCreature::IsFall()
{
	return mFightStatus.Fall;
}


fvoid					GameCreature::SetFall( fbool b )
{
	mFightStatus.Fall = b;
}


fvoid					GameCreature::ClearFightStatus()
{
	mFightStatus.Fall = F_FALSE;
	mFightStatus.Status = SAST_NONE;
}


fbool					GameCreature::CheckStatus( SAStatusType s )
{
	return mFightStatus.Status == s;
}


fvoid					GameCreature::SetStatus( SAStatusType s )
{
	mFightStatus.Status = s;
}


fbool					GameCreature::CheckState( GameCreatureState state )
{
	return mState == state;
}


fvoid					GameCreature::SetState( GameCreatureState state )
{
	mState = state;
}


GameCreature::GameCreatureState		GameCreature::GetState()
{
	return mState;
}


fvoid					GameCreature::AddEXP( fint32 exp )
{
	mTempExp += exp;
}


fvoid					GameCreature::CheckLevelUp()
{
	mData.EXP += mTempExp;

	while ( mData.EXP >= gExpConfig->EXP[ mData.Level + 1 ] )
	{
		mData.EXP -= gExpConfig->EXP[ mData.Level + 1 ];
		mData.Level++;
		mData.LevelUpPoint += MAX_LEVELUP_POINT;
	}

	mData.NEXTEXP = gExpConfig->EXP[ mData.Level + 1 ];
}


fint32					GameCreature::GetExp()
{
	return 0;
}


CreatureMoveData&		GameCreature::GetMoveData()
{
	return mMoveData;
}


CreatureData&			GameCreature::GetData()
{
	return mData;
}


CreatureFightData&		GameCreature::GetFightData()
{
	return mFightData;
}


BattleSessionCommand&	GameCreature::GetCommand()
{
	return mCommand;
}


GameTeam*				GameCreature::GetTeam()
{
	return mTeam;
}

fvoid					GameCreature::SetTeam( GameTeam* team )
{
	mTeam = team;
}


//////////////////////////////////////////////////////////////////////////

fbool					GameCreature::IsFighting()
{
	return mState == GCSFIGHT;
}


fvoid					GameCreature::StartFight()
{
	mTempExp = 0;

	mMoveData.EndMove();

	SetState( GCSFIGHT );
}


fvoid					GameCreature::EndFight()
{
	SetState( GCSSTAND );

	ClearFightStatus();
}


fvoid					GameCreature::InitBaseData()
{
	mData.Base.Attack = mData.Strength;
	mData.Base.Defence = mData.Toughness;
	mData.Base.Quick = mData.Dexterity;

	mData.Base.MAXHP = GETMAXHP( mData.Vitality , mData.Strength , mData.Toughness , mData.Dexterity );
	mData.Base.MAXMP = 100;
}


fvoid					GameCreature::UpdateFightData()
{
	mFightData.Base.Attack = mData.Base.Attack;
	mFightData.Base.Defence = mData.Base.Defence;
	mFightData.Base.Quick = mData.Base.Quick;
	mFightData.Base.Charm = mData.Base.Charm;

	mFightData.Base.MAXHP = mData.Base.MAXHP;
	mFightData.Base.MAXMP = mData.Base.MAXMP;  

	mFightData.Base.Earth = mData.Base.Earth;
	mFightData.Base.Water = mData.Base.Water;
	mFightData.Base.Fire = mData.Base.Fire;
	mFightData.Base.Wind = mData.Base.Wind;

	mFightData.Poison = 0;
	mFightData.Paralysis = 0;
	mFightData.Sleep = 0;
	mFightData.Stone = 0;
	mFightData.Drunk = 0;
	mFightData.Confusion = 0;

}


fvoid				GameCreature::AddHp( fint32 hp )
{
	mFightData.Base.HP += hp;

	if ( mFightData.Base.HP > mFightData.Base.MAXHP )
	{
		mFightData.Base.HP = mFightData.Base.MAXHP;
	}

	if ( mFightData.Base.HP < 0 )
	{
		mFightData.Base.HP = 0;
	}
}


fvoid				GameCreature::AddMp( fint32 mp )
{
	mFightData.Base.MP += mp;

	if ( mFightData.Base.MP > mFightData.Base.MAXMP )
	{
		mFightData.Base.MP = mFightData.Base.MAXMP;
	}

	if ( mFightData.Base.MP < 0 )
	{
		mFightData.Base.MP = 0;
	}
}


fvoid				GameCreature::AddCharm( fint32 c )
{
	mFightData.Base.Charm += c;

	if ( mFightData.Base.Charm > 100 )
	{
		mFightData.Base.Charm = 100;
	}

	if ( mFightData.Base.Charm < 0 )
	{
		mFightData.Base.Charm = 0;
	}
}


